﻿using System;

using System.Collections.Generic;
using System.Text;
using Silvermoon.Animations;
using System.Drawing;

namespace Silvermoon.UI
{

    public delegate void ValueSetterDelegate<C, T>(C obj, T value) where C : IPropertyObject;
    public delegate T ValueGetterDelegate<C, T>(C obj) where C : IPropertyObject;

    public abstract class PropertyAccessor
    {

        private static int globalIndex;

        /// <summary>
        /// index that uniquely identifies the accessor.
        /// </summary>
        public readonly int Index = globalIndex++;


        /// <summary>
        /// Registers a new PropertyAccessor.
        /// </summary>
        /// <typeparam name="T">Type of Property to access.</typeparam>
        /// <param name="property">Name of property.</param>
        /// <param name="getter">Getter method to access the value.</param>
        /// <param name="setter">Setter method to change the value.</param>
        /// <returns>New PropertyAccessor.</returns>
        public static PropertyAccessor<C, T> Register<C, T>(string property, ValueGetterDelegate<C, T> getter, ValueSetterDelegate<C, T> setter) where C : IPropertyObject
        {
            PropertyAccessor<C, T> accessor = new PropertyAccessor<C, T>(property, getter, setter);
            return accessor;
        }


        public abstract void BeginAnimation(IPropertyObject obj, Transition transition);

        internal abstract void BeginAnimation(IPropertyObject obj, Transition transition, int duration);

        public abstract void EndAnimation(IPropertyObject obj, int Duration);

        public abstract void StopAnimation(IPropertyObject obj);

        public override bool Equals(object obj)
        {
            PropertyAccessor a = obj as PropertyAccessor;
            if (a==null) return false;
            return this.Index == a.Index;
        }

        public override int GetHashCode()
        {
            return Index;
        }



        public abstract void Prepare(Animation a,IPropertyObject obj);
    }

}
